#ifndef __MYSQL_CLIENT__
#define __MYSQL_CLIENT__

#include <map>
#include <vector>
#include <string>
#include <mysql.h>

class Mysql
{
private:
	MYSQL mysql_connection;
	MYSQL *mysql_ptr;

	const char *_name;
	const char *_host;
	const char *_user;
	const char *_pass;

	unsigned int _port;

public:
	Mysql(const char*, const char*,
		const char* = NULL, const char* = NULL, unsigned int = 3306);

	~Mysql();

public:
	inline bool available() { return mysql_ptr && mysql_ping(mysql_ptr) == 0; }

	bool execute(const char* sql, const size_t len);

	bool query(const char* sql, MYSQL_RES*& res);

	bool query(const char* sql, std::vector< std::map<std::string, std::string> >& result);

	bool connect();

	void disconnect();
private:
	bool __real_query(const char* sql, const size_t len);
};

#endif // --__MYSQL_DB__

